package org.gpp.proj1.test.map;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.gpp.proj1.map.MalformedMapFileException;
import org.gpp.proj1.map.combat.CombatMap;
import org.gpp.proj1.map.combat.Decoration;
import org.gpp.proj1.map.combat.ProceduralTexture;
import org.gpp.proj1.map.combat.SplatTexture;
import org.gpp.proj1.map.parser.CombatMapFileParser;

/**
 * 
 * Why we must program in english?
 * Facade for Acceptance tests
 * @author Pablo Diego
 *
 */
public class CombatMapFileParserFacade {

	private Map<String, CombatMap> maps;
	
	public CombatMapFileParserFacade(){
		
		this.maps = new HashMap<String, CombatMap>();
	}
	
	/**
	 * @param mapFile
	 * @return
	 * @throws IOException
	 * @throws MalformedMapFileException
	 */
	public String loadMap(String mapFile) throws IOException, MalformedMapFileException {
		
		File f = new File(mapFile);
		String mapName = f.getName().substring(0, f.getName().lastIndexOf("."));
		
		this.maps.put(mapName, CombatMapFileParser.parseFile(mapFile));
		
		return mapName;
	}
	
	/**
	 * 
	 * @param mapName
	 * @return
	 */
	public String getHeightMapFileName(String mapName){
		
		CombatMap map = this.maps.get(mapName);
		return map.heightMapFile;
	}
	
	/**
	 * 
	 * @param mapName
	 * @return
	 */
	public float getHeightMultiplier(String mapName){
		
		CombatMap map = this.maps.get(mapName);
		return map.heightMultiplier;
	}
	
	/**
	 * 
	 * @param mapName
	 * @param number
	 * @param parameter
	 * @return
	 */
	public String getProceduralTextureParameter(String mapName, int number, String parameter){
		
		CombatMap map = this.maps.get(mapName);
		ProceduralTexture texture = map.proceduralTextures.get(number);
		
		if( parameter.equals("low") ){
			
			return "" + texture.low;
		}
		else if( parameter.equals("optimal") ){
			
			return "" + texture.optimal;
		}
		else if( parameter.equals("high") ){
			
			return "" + texture.high;
		}
		else if( parameter.equals("file") ){

			return "" + texture.texture;
		}
		
		return "";
	}
	
	/**
	 * 
	 * @param mapName
	 * @param number
	 * @param parameter
	 * @return
	 */
	public String getSplatTextureParameter(String mapName, int number, String parameter){
		
		CombatMap map = this.maps.get(mapName);
		SplatTexture texture = map.splatTextures.get(number);
		
		if( parameter.equals("mask") ){
			
			return "" + texture.mask;
		}
		else if( parameter.equals("file") ){
			
			return "" + texture.texture;
		}
		
		return "";
	}
	
	/**
	 * 
	 * @param mapName
	 * @param number
	 * @param parameter
	 * @return
	 */
	public String getDecorationParameter(String mapName, int number, String parameter){
		
		CombatMap map = this.maps.get(mapName);
		Decoration decoration = map.decorations.get(number);
		
		if( parameter.equals("model") ){
			
			return "" + decoration.model;
		}
		else if( parameter.equals("texture") ){
			
			return "" + decoration.texture;
		}
		else if( parameter.equals("scale") ){
			
			return "" + decoration.scale;
		}
		
		return "";
	}
	
}
